package com.demo.Controller;

import com.demo.entity.Grade;
import com.demo.Repository.GradeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/grades")
public class GradeController {

    @Autowired
    private GradeRepository gradeRepository;

    @GetMapping("/listAll")
    public List<Grade> listAll() {
        return (List<Grade>) gradeRepository.findAll();
    }

    @GetMapping("/getByCourseId/{courseId}")
    public List<Grade> getByCourseId(@PathVariable Long courseId) {
        // 使用正确的方法名
        return gradeRepository.findByCourseId(courseId);
    }

    @PutMapping("/update")
    public Grade update(@RequestBody Grade grade) {
        // 更新成绩逻辑
        return gradeRepository.save(grade);
    }

    @GetMapping("/getByRange/{minScore}/{maxScore}")
    public List<Grade> getByRange(@PathVariable float minScore, @PathVariable float maxScore) {
        return gradeRepository.findByScoreBetween(minScore, maxScore);
    }
}
//孙伟景22090201135